/*
 * Copyright (c) 1994-2017, Joyoung Stock CO.LTD.
 * The FWJR Project.
 * All Rights Reserved.
 */

package com.hepinghospital.user.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.NonNull;

import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseDialogFragment;


/**
 * 图片选择方式对话框
 */
public class SelectPicModeDialog extends BaseDialogFragment implements View.OnClickListener {
    private OnItemClickListener mListener;
    private Dialog mDialog;

    public static SelectPicModeDialog newInstance() {
        return new SelectPicModeDialog();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDialog = super.onCreateDialog(savedInstanceState);
        mDialog.setCancelable(false);
        Window window = mDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
        }
        return mDialog;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.common_select_pic_mode_layout, container, false);
        mView.setMinimumWidth(mScreenWidth);
        mView.findViewById(R.id.txt_take_photo).setOnClickListener(this);
        mView.findViewById(R.id.txt_pick_from_album).setOnClickListener(this);
        mView.findViewById(R.id.txt_cancel).setOnClickListener(this);
        return mView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getDialog().setCanceledOnTouchOutside(false);
    }

    public interface OnItemClickListener {
        void takePhotoClick();

        void pickFromAlbumClick();
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.txt_take_photo:
                mListener.takePhotoClick();
                dismiss();
                break;
            case R.id.txt_pick_from_album:
                mListener.pickFromAlbumClick();
                dismiss();
                break;
            case R.id.txt_cancel:
                dismiss();
                break;
            default:
                break;
        }
    }

    public boolean isShowing() {
        return mDialog != null && mDialog.isShowing();
    }
}
